<%
var headContent = {
include("/pages/template/head.html"){}
%>

<script type="text/javascript">
    var oper;
    jQuery(function ($) {
        // 页面方法
        oper = {
            width: 750,
            height: 400,
            form: document.form1,
            list: function () {
                var url = 'quartz/jobs/list';
                this.form.action = url;
                this.form.submit();
            },
            add: function () {
                var url = 'quartz/jobs/add';
                var title = '新增任务';
                Iframe(url, this.width, this.height, title);
            },
            edit: function (id) {
                var url = 'quartz/jobs/edit/' + id;
                var title = '编辑';
                Iframe(url, this.width, 600, title);
                //Iframe(url, this.width, this.height, title, false, false, false, EmptyFunc);
            },
            del: function (pId) {
                var url = 'quartz/jobs/deleteJob/' + pId;
                Confirm('确定删除', function () {
                    $.ajax({
                        type: "POST",
                        url: url,
                        dataType: "json",
                        success: function (data) {
                            alert( data.msg);
                            paginator();
                        },
                        error: function (msg) {
                            alert("error");
                        }
                    });
                    return true;
                });
            },
            addJob: function (id) {
                var url = 'quartz/jobs/addJob/' + id;
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        alert( data.msg);
                        paginator();
                    },
                    error: function (msg) {
                        alert("error");
                    }
                });
            },
            stopJobs: function (id) {
                var url = 'quartz/jobs/stopJobs/' + id;
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        alert( data.msg);
                        paginator();
                    },
                    error: function (msg) {
                        alert("error");
                    }
                });
            },
            runJobsOnce: function (id) {
                var url = 'quartz/jobs/runJobsOnce/' + id;
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        alert( data.msg);
                        paginator();
                    },
                    error: function (msg) {
                        alert("error");
                    }
                });
            }
        };
        //显示Menu索引
        showMenu('page_job');
        showMenu('page_job_jobs');
    });

    //分页
    var paginator = function (page) {
        oper.list();
    };
</script>

<%
};

var bodyContent = {
%>
<form name="form1" action="" method="post" class="form-inline" role="form">
    <!-- 菜单 -->
    <% include("/pages/template/menu.html"){} %>

    <div class="tableSearch">
        <% //查询列表 %>
        <button type="button" class="btn btn-default" style="display: none" onclick="oper.list();" name="search">
        </button>
        <button type="button" class="btn btn-default" onclick="oper.add();">
            <span class="glyphicon glyphicon-plus"></span> 新 增
        </button>
    </div>

    <!-- 数据列表 -->
    <table class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <th>序号</th>
            <% // 列表头部 %>
            <th name="jobName">任务名称</th>
            <th name="jobContent">任务内容（描述）</th>
            <th name="jobclassUids">执行类</th>
            <th name="quartztimes">定时运行时间（Quartz表达式）</th>
            <th name="jobState" style="width: 50px;">状态</th>
            <th name="createDate" style="width: 90px;">创建时间</th>
            <th name="remark" >备注</th>
            <th style="width: 195px;">操作</th>
        </tr>
        </thead>
        <tbody>
        <% for(item in page.list) {%>
        <tr>
            <td>${itemLP.index }</td>
            <% // 列表内容 %>
            <td>${item.jobName}</td>
            <td>${item.jobContent}</td>
            <td>${item.jobclassUids}</td>
            <td>${item.quartztimes}</td>

            <% if(item.jobState =='0') {%>
            <td>启用</td>
            <%} else if(item.jobState =='1') {%>
            <td>禁用</td>
            <%}%>
            <td>${item.createDate}</td>
            <td>${item.remark}</td>
            <td>
                <a href="javascript:void(0);" class="btn btn-sm btn-warning" onclick="oper.del('${item.uids}');">删除</a>
                <% if(item.jobState =='0') {%>
                <a href="javascript:void(0);" class="btn btn-sm btn-warning" onclick="oper.stopJobs('${item.uids}');">停用</a>
                <a href="javascript:void(0);" class="btn btn-sm btn-success" onclick="oper.runJobsOnce('${item.uids}');">执行一次</a>
                <%} else if(item.jobState =='1') {%>
                <a href="javascript:void(0);" class="btn btn-sm btn-success" onclick="oper.edit('${item.uids}');">编辑</a>
                <a href="javascript:void(0);" class="btn btn-sm btn-primary" onclick="oper.addJob('${item.uids}');">启动</a>
                <%}%>
                <!--<a href="javascript:void(0);" class="btn btn-sm btn-primary" onclick="oper.edit('${item.UIDS}');">修改</a>
                -->
            </td>
        </tr>
        <% } %>
        </tbody>
    </table>
    <%include("/pages/includes/paginator.html"){} %>
</form>
<%}; %>


<% layout("/pages/template/_layout.html",{head:headContent,body:bodyContent}){ %>
<%} %>
